<?php
class analysisController extends RPHP_Controller
{
    //权限前缀
    protected $_pvprefix = "analysis";

    //新增用户统计
    public function addmembertotal()
    {
        $priv  = array($this->_pvprefix . "_amt");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);

        if ($auth) {
            $para = array();

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            $this->view->data = $model->getMemberTotal($para);

            $this->view->auth = $auth;
            $this->display();

        }
    }

    //新增用户导出
    public function member_export()
    {
        $priv = array($this->_pvprefix . "_amt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $para = array();

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }


            $orderData =   $model->getMemberTotal($para);

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();

                //设置excel属性基本信息
                $excel->getProperties()->setCreator("LEHUO")
                    ->setLastModifiedBy("LEHUO")
                    ->setTitle("LEHUO")
                    ->setSubject("新增用户统计")
                    ->setDescription("")
                    ->setKeywords("新增用户统计")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("新增用户统计");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '新增用户统计');
                //填入表头副标题
                $excel->getActiveSheet()->setCellValue('A2', '新增用户统计');
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:M1');
                $excel->getActiveSheet()->mergeCells('A2:M2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M','N');
                $tableheader = array('用户', '直推人数', '西客会员', '365会员', '良品e店', '西海代理', '银牌创客', '金牌创客','业务经理', '区域总监','区县代理','团队业绩','365及以上消费业绩', '西客会员消费业绩');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }

                $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                $excel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('P')->setWidth(20);



                    $line =  $excel_H;
                    $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $line, $orderData['team_num']);
                    $excel->getActiveSheet()->setCellValue('B' . $line, ' ' .$orderData['zt_num'] . " ");
                    $excel->getActiveSheet()->setCellValue('C' . $line, $orderData['member_level0_num']);
                    $excel->getActiveSheet()->setCellValue('D' . $line, $orderData['member_level1_num'] . " ");
                    $excel->getActiveSheet()->setCellValue('E' . $line, $orderData['member_level2_num']);
                    $excel->getActiveSheet()->setCellValue('F' . $line, $orderData['member_level3_num'] . ' ');
                    $excel->getActiveSheet()->setCellValue('G' . $line, $orderData['maker_level1_num']);
                    $excel->getActiveSheet()->setCellValue('H' . $line, $orderData['maker_level2_num']);
                    $excel->getActiveSheet()->setCellValue('I' . $line, $orderData['maker_level3_num']);
                    $excel->getActiveSheet()->setCellValue('J' . $line,$orderData['maker_level4_num']);
                    $excel->getActiveSheet()->setCellValue('K' . $line, $orderData['maker_level5_num']);
                    $excel->getActiveSheet()->setCellValue('L' . $line, $orderData['team_money']);
                    $excel->getActiveSheet()->setCellValue('M' . $line,$orderData['member_level_money']);
                    $excel->getActiveSheet()->setCellValue('N' . $line, $orderData['member_level0_money']);


                    $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    // $total_money += $v['total'];


                // 合计金额
                /* $new_line = $line + 1;
                 $excel->getActiveSheet()->mergeCells('A' . $new_line . ':J' . $new_line);
                 $excel->getActiveSheet()->getRowDimension($new_line)->setRowHeight(24);
                 $excel->getActiveSheet()->setCellValue('A' . $new_line, '金额合计：');
                 $excel->getActiveSheet()->getStyle('A' . $new_line . ':M' . $new_line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                 $excel->getActiveSheet()->getStyle('A' . $new_line)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                 $excel->getActiveSheet()->setCellValue('K' . $new_line, $total_money);*/

                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                            //'color' => array('argb' => 'FFFF0000'),
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="新增用户统计' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                header("Content-type: text/html; charset=utf-8");
                echo "没有要导出的数据";die;
            }

        }

    }

    //会员足迹
    public function memberfootmark()
    {
        $priv  = array($this->_pvprefix . "_fm");
        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $para = array();
            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            $this->view->data = $model->getMemberFootMark($para, $page);
            //dd($this->view->data);
            //获取页码
            if ($this->view->data['maxpage'] > 1) {
                $this->view->data['spage'] = $model->fun->spage($this->view->data['page'], $this->view->data['maxpage']);
            }

            $this->view->auth = $auth;
            $this->display();

        }
    }

    //会员足迹导出
    public function memberfoot_export()
    {
        $priv = array($this->_pvprefix . "_fm");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $para = array();
            if (intval($_GET['page']) > 0) {
                $page = intval($_GET['page']);
            } else {
                $page = 1;
            }

            if (!empty($_GET['keyword'])) {
                $para['keyword'] = addslashes(stripslashes(trim($_GET['keyword'])));
            }

            if ($_GET['start_time'] != "") {
                $start_time = strtotime($_GET['start_time']);
                if ($start_time > 0) {
                    $para['start_time'] = $start_time;
                }
            }
            if ($_GET['end_time'] != "") {
                $end_time = strtotime($_GET['end_time']);
                if ($end_time > 0) {
                    $para['end_time'] = $end_time;
                }

            }

            $data = $model->getMemberFootMark($para, $page);
            if ($data['data']) {
                foreach ($data['data'] as $k => $v) {
                    $orderData[] = array(
                        'recode'         => $data['members'][$v['uid']]['recode'],
                        'realname'       => $data['members'][$v['uid']]['realname'],
                        'name'       => $data['members'][$v['uid']]['name'],
                        'mobile'         => $data['members'][$v['uid']]['mobile'],
                        'member_level'        =>  $this->c['member_level_t'][$data['members'][$v['uid']]['member_level']],
                        'maker_level'     => $this->c['maker'][$data['members'][$v['uid']]['maker_level']],
                        'create_time'       => date('Y-m-d H:i:s',$v['create_time']),
                        'goods_name'    => $data['goods'][$v['goods_id']] ,

                    );
                }

            }

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();

                //设置excel属性基本信息
                $excel->getProperties()->setCreator("LEHUO")
                    ->setLastModifiedBy("LEHUO")
                    ->setTitle("LEHUO")
                    ->setSubject("用户足迹")
                    ->setDescription("")
                    ->setKeywords("用户足迹")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("用户足迹");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '用户足迹');
                //填入表头副标题
                //$excel->getActiveSheet()->setCellValue('A2', '用户足迹');
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:M1');
                $excel->getActiveSheet()->mergeCells('A2:M2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
                $tableheader = array('邀请码', '会员昵称', '姓名', '手机号码', '365职级', '创客职级', '来访时间', '浏览内容');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }

                $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
                $excel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
                $excel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
                $excel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('H')->setWidth(80);
                $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('P')->setWidth(20);
                foreach ($orderData as $num => $v) {
                    $line = $num + $excel_H;
                    $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $line, $v['recode']);
                    $excel->getActiveSheet()->setCellValue('B' . $line, ' ' . $v['realname'] . " ");
                    $excel->getActiveSheet()->setCellValue('C' . $line, $v['name']);
                    $excel->getActiveSheet()->setCellValue('D' . $line, $v['mobile'] . " ");
                    $excel->getActiveSheet()->setCellValue('E' . $line, $v['member_level']);
                    $excel->getActiveSheet()->setCellValue('F' . $line, $v['maker_level']);
                    $excel->getActiveSheet()->setCellValue('G' . $line, $v['create_time']);
                    $excel->getActiveSheet()->setCellValue('H' . $line, $v['goods_name']);
                    $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

                }


                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                            //'color' => array('argb' => 'FFFF0000'),
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="用户足迹' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                header("Content-type: text/html; charset=utf-8");
                echo "没有要导出的数据";die;
            }

        }

    }


    
    //销售走势
    public function sales()
    {
        $priv = array($this->_pvprefix . "_sal");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $start_time = strtotime($_GET['start_time']);
            $end_time   = strtotime($_GET['end_time']);
            if ($end_time) {
                $end_time = $end_time + 24 * 3600;
            }

            $this->view->chart = $model->getHomeChartData($start_time, $end_time);

            $this->display();
        }
    }

    //静态表
    public function  staticlist(){

        $priv = array($this->_pvprefix . "_scl");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->cate = $model->getCategory();

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['start_time'] != "") {
                $para['start_time'] = strtotime($_GET['start_time']);
            }

            if ($_GET['end_time'] != "") {
                $para['end_time'] = strtotime($_GET['end_time'] . " 23:59:59");
            }

            if ($_GET['goods_id'] != "" ) {
                $para['goods_id'] = intval($_GET['goods_id']);
            }


            $this->view->data = $model->getStaticList($para);

            $this->display();
        }

    }

    //静态表导出
    public function static_export()
    {
        $priv = array($this->_pvprefix . "_scl");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->cate = $model->getCategory();

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['start_time'] != "") {
                $para['start_time'] = strtotime($_GET['start_time']);
            }

            if ($_GET['end_time'] != "") {
                $para['end_time'] = strtotime($_GET['end_time'] . " 23:59:59");
            }

            if ($_GET['goods_id'] != "" ) {
                $para['goods_id'] = intval($_GET['goods_id']);
            }


            $data =  $model->getStaticList($para);
            if ($data['data']) {
                foreach ($data['data'] as $k => $v) {
                    $orderData[] = array(
                        'supplierid'         => $v['supplierid'],
                        'goods_id'       => $v['goods_id'],
                        'goods_name'       => $v['goods_name'],
                        'cate_name1'         => $v['cate_name1'],
                        'cate_name2'        =>  $v['cate_name2'],
                        'goods_type'     => $v['goods_type'],
                        'goods_price'       => $v['goods_price'],
                        'purchase_price'    => $v['purchase_price'],
                        'money'   => $v['money'],
                        'sale_money'          =>$v['sale_money'] ,
                        'gross_profit'            => $v['gross_profit'],
                        'profit_rate'          => ($v['profit_rate']*100)."%" ,
                        'fugou_level3' =>$v['fugou_level3'],
                        'fugou_level3' =>$v['fugou_level3'],
                        'price_me' =>$v['price_me'],
                        'price_level1' =>$v['price_level1'],
                        'give_coupon' =>$v['give_coupon'],

                    );
                }

            }

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();

                //设置excel属性基本信息
                $excel->getProperties()->setCreator("LEHUO")
                    ->setLastModifiedBy("LEHUO")
                    ->setTitle("LEHUO")
                    ->setSubject("静态表")
                    ->setDescription("")
                    ->setKeywords("静态表")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("静态表");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '静态表');
                //填入表头副标题
                $excel->getActiveSheet()->setCellValue('A2', '供应商:' .$data['supplier_num'].'个 商品ID:'.$data['goods_num'].'个 ');
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:M1');
                $excel->getActiveSheet()->mergeCells('A2:M2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M','N','O','P','Q');
                $tableheader = array('供应商ID', '商品ID', '商品名称', '一级分类', '二级分类', '商品类型', '零售价', '进货价','代金券', '返硒豆','推广赚','良品e店','西海代理', '销售额', '毛利润额', '利润百分比');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }

                $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('C')->setWidth(80);
                $excel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
                $excel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
                $excel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('P')->setWidth(20);


                $total_money = 0;
                foreach ($orderData as $num => $v) {
                    $line = $num + $excel_H;
                    $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $line, $v['supplierid']);
                    $excel->getActiveSheet()->setCellValue('B' . $line, ' ' . $v['goods_id'] . " ");
                    $excel->getActiveSheet()->setCellValue('C' . $line, $v['goods_name']);
                    $excel->getActiveSheet()->setCellValue('D' . $line, $v['cate_name1'] . " ");
                    $excel->getActiveSheet()->setCellValue('E' . $line, $v['cate_name2']);
                    $excel->getActiveSheet()->setCellValue('F' . $line, $v['goods_type'] . ' ');
                    $excel->getActiveSheet()->setCellValue('G' . $line, $v['goods_price']);
                    $excel->getActiveSheet()->setCellValue('H' . $line, $v['purchase_price']);
                    $excel->getActiveSheet()->setCellValue('I' . $line, $v['give_coupon']);
                    $excel->getActiveSheet()->setCellValue('J' . $line, $v['price_me']);
                    $excel->getActiveSheet()->setCellValue('K' . $line, $v['price_level1']);
                    $excel->getActiveSheet()->setCellValue('L' . $line, $v['fugou_level2']);
                    $excel->getActiveSheet()->setCellValue('M' . $line, $v['fugou_level3']);
                    $excel->getActiveSheet()->setCellValue('N' . $line, $v['sale_money']);
                    $excel->getActiveSheet()->setCellValue('O' . $line, $v['gross_profit']);
                    $excel->getActiveSheet()->setCellValue('P' . $line, $v['profit_rate']);

                    $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                   // $total_money += $v['total'];
                }

                // 合计金额
               /* $new_line = $line + 1;
                $excel->getActiveSheet()->mergeCells('A' . $new_line . ':J' . $new_line);
                $excel->getActiveSheet()->getRowDimension($new_line)->setRowHeight(24);
                $excel->getActiveSheet()->setCellValue('A' . $new_line, '金额合计：');
                $excel->getActiveSheet()->getStyle('A' . $new_line . ':M' . $new_line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                $excel->getActiveSheet()->getStyle('A' . $new_line)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                $excel->getActiveSheet()->setCellValue('K' . $new_line, $total_money);*/

                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                            //'color' => array('argb' => 'FFFF0000'),
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="静态表' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                header("Content-type: text/html; charset=utf-8");
                echo "没有要导出的数据";die;
            }

        }

    }

    //动态表
    public function  dynamiclist(){

        $priv = array($this->_pvprefix . "_dcl");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->cate = $model->getCategory();

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if ($_GET['goods_id'] != "" ) {
                $para['goods_id'] = intval($_GET['goods_id']);
            }
            if ($_GET['caid'] != "") {
                $para['caid'] = intval($_GET['caid']);
            }

            $this->view->data = $model->getDynamicList($para);

            $this->display();
        }

    }

    //动态表导出
    public function dynamic_export()
    {
        $priv = array($this->_pvprefix . "_dcl");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
           // $this->view->cate = $model->getCategory();

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }

            if ($_GET['goods_id'] != "" ) {
                $para['goods_id'] = intval($_GET['goods_id']);
            }
            if ($_GET['caid'] != "") {
                $para['caid'] = intval($_GET['caid']);
            }


            $data =  $model->getDynamicList($para);
            if ($data['data']) {
                foreach ($data['data'] as $k => $v) {
                    $orderData[] = array(
                        'rank'         => ++$k,
                        'supplierid'         => $v['supplierid'],
                        'goods_id'       => $v['goods_id'],
                        'goods_name'       => $v['goods_name'],
                        'purchase_price'         => $v['purchase_price'],
                        'average_price'        =>  $v['average_price'],
                        'goods_number'     => $v['goods_number'],
                        'sale_money'          =>$v['sale_money'] ,
                        'gross_profit'            => $v['gross_profit'],
                        'profit_rate'          => ($v['profit_rate']*100)."%" ,

                    );
                }

            }

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();

                //设置excel属性基本信息
                $excel->getProperties()->setCreator("LEHUO")
                    ->setLastModifiedBy("LEHUO")
                    ->setTitle("LEHUO")
                    ->setSubject("动态表")
                    ->setDescription("")
                    ->setKeywords("动态表")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("动态表");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '动态表');
                //填入表头副标题
                $excel->getActiveSheet()->setCellValue('A2', '客单价:' .$data['price']);
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:M1');
                $excel->getActiveSheet()->mergeCells('A2:M2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
                $tableheader = array('排名','供应商ID', '商品ID', '商品名称', '成本价', '销售均价', '销售数量',  '销售额', '毛利润额', '利润百分比');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }

                $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                $excel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('D')->setWidth(80);
                $excel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
                $excel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('L')->setWidth(20);

                $total_number = 0;
                $total_sale_money = 0;
                $total_gross_profit = 0;
                foreach ($orderData as $num => $v) {
                    $line = $num + $excel_H;
                    $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                    $excel->getActiveSheet()->setCellValue('A' . $line,$v['rank']);
                    $excel->getActiveSheet()->setCellValue('B' . $line,  $v['supplierid']);
                    $excel->getActiveSheet()->setCellValue('C' . $line, ' ' . $v['goods_id'] . " ");
                    $excel->getActiveSheet()->setCellValue('D' . $line, $v['goods_name'] . " ");
                    $excel->getActiveSheet()->setCellValue('E' . $line, $v['purchase_price']);
                    $excel->getActiveSheet()->setCellValue('F' . $line, $v['average_price']);
                    $excel->getActiveSheet()->setCellValue('G' . $line, $v['goods_number']);
                    $excel->getActiveSheet()->setCellValue('H' . $line, $v['sale_money']);
                    $excel->getActiveSheet()->setCellValue('I' . $line, $v['gross_profit']);
                    $excel->getActiveSheet()->setCellValue('J' . $line, $v['profit_rate']);

                    $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                    $total_number += $v['goods_number'];
                    $total_sale_money += $v['sale_money'];
                    $total_gross_profit += $v['gross_profit'];
                }

                // 合计金额
                 $new_line = $line + 1;
                 $excel->getActiveSheet()->mergeCells('A' . $new_line . ':F' . $new_line);
                 $excel->getActiveSheet()->getRowDimension($new_line)->setRowHeight(24);
                 $excel->getActiveSheet()->setCellValue('A' . $new_line, '合计：');
                 $excel->getActiveSheet()->getStyle('A' . $new_line . ':M' . $new_line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                 $excel->getActiveSheet()->getStyle('A' . $new_line)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                 $excel->getActiveSheet()->setCellValue('G' . $new_line, $total_number);
                $excel->getActiveSheet()->setCellValue('H' . $new_line, $total_sale_money);
                $excel->getActiveSheet()->setCellValue('I' . $new_line, $total_gross_profit);

                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                            //'color' => array('argb' => 'FFFF0000'),
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="动态表' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                header("Content-type: text/html; charset=utf-8");
                echo "没有要导出的数据";die;
            }

        }

    }

    //新增重销统计
    public function moresell()
    {
        $priv = array($this->_pvprefix . "_cxt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->cate = $model->getPcate();

            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['start_time'] != "") {
                $para['start_time'] = strtotime($_GET['start_time']);
            }

            if ($_GET['end_time'] != "") {
                $para['end_time'] = strtotime($_GET['end_time'] . " 23:59:59");
            }

            if ($_GET['caids'] != "") {
                $para['caids'] = $_GET['caids'];
            }

            $this->view->data = $model->getMoreSell($para);

            $this->display();
        }

    }

    public function sell_export()
    {

        $priv = array($this->_pvprefix . "_cxt");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            if ($_GET['keyword'] != "") {
                $keyword = addslashes(trim($_GET['keyword']));
                if ($keyword != '') {
                    $para['keyword'] = $keyword;
                }

            }
            if ($_GET['start_time'] != "") {
                $para['start_time'] = strtotime($_GET['start_time']);
            }

            if ($_GET['end_time'] != "") {
                $para['end_time'] = strtotime($_GET['end_time'] . " 23:59:59");
            }

            if ($_GET['caids'] != "") {
                $para['caids'] = $_GET['caids'];
            }

            $orderData = $model->getMoreSell($para);

            if ($orderData) {
                RPHP::loadClass("PHPExcel", "extend/PHPExcel/Classes");
                $excel = new PHPExcel();

                //设置excel属性基本信息
                $excel->getProperties()->setCreator("LEHUO")
                    ->setLastModifiedBy("LEHUO")
                    ->setTitle("LEHUO")
                    ->setSubject("新增重销统计")
                    ->setDescription("")
                    ->setKeywords("新增重销统计")
                    ->setCategory("");
                $excel->setActiveSheetIndex(0);
                $excel->getActiveSheet()->setTitle("新增重销统计");
                //填入表头主标题
                $excel->getActiveSheet()->setCellValue('A1', '新增重销统计');
                //填入表头副标题
                $excel->getActiveSheet()->setCellValue('A2', '新增重销统计');
                //合并表头单元格
                $excel->getActiveSheet()->mergeCells('A1:M1');
                $excel->getActiveSheet()->mergeCells('A2:M2');

                //设置表头行高
                $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
                $excel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
                $excel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

                //设置表头字体
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
                $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
                $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
                $excel->getActiveSheet()->getStyle('A3:M3')->getFont()->setBold(true);
                $letter      = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M');
                $tableheader = array('','自购',  '西客会员', '365会员', '良品e店', '西海代理', '银牌创客', '金牌创客','业务经理', '区域总监','区县代理','365及以上消费业绩', '团队业绩');
                $excel_H     = 4;
                for ($i = 0; $i < count($tableheader); $i++) {
                    $excel->getActiveSheet()->setCellValue("$letter[$i]3", "$tableheader[$i]");
                }

                $excel->getActiveSheet()->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('B')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('F')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
                $excel->getActiveSheet()->getStyle('M')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

                $excel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
                $excel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('K')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('L')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('M')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('N')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('O')->setWidth(20);
                $excel->getActiveSheet()->getColumnDimension('P')->setWidth(20);



                $line = $excel_H;
                $excel->getActiveSheet()->getRowDimension($line)->setRowHeight(24);
                $excel->getActiveSheet()->setCellValue('A' . $line, '业绩');
                $excel->getActiveSheet()->setCellValue('B' . $line, ' ' .$orderData['my_money'] );
                $excel->getActiveSheet()->setCellValue('C' . $line, $orderData['member_level0_money']);
                $excel->getActiveSheet()->setCellValue('D' . $line, $orderData['member_level1_money']);
                $excel->getActiveSheet()->setCellValue('E' . $line, $orderData['member_level2_money']);
                $excel->getActiveSheet()->setCellValue('F' . $line, $orderData['member_level3_money']);
                $excel->getActiveSheet()->setCellValue('G' . $line, $orderData['maker_level1_money']);
                $excel->getActiveSheet()->setCellValue('H' . $line, $orderData['maker_level2_money']);
                $excel->getActiveSheet()->setCellValue('I' . $line, $orderData['maker_level3_money']);
                $excel->getActiveSheet()->setCellValue('J' . $line,$orderData['maker_level4_money']);
                $excel->getActiveSheet()->setCellValue('K' . $line, $orderData['maker_level5_money']);
                $excel->getActiveSheet()->setCellValue('L' . $line, $orderData['member_level_money']);
                $excel->getActiveSheet()->setCellValue('M' . $line,$orderData['team_money']);
                $excel->getActiveSheet()->getStyle('A' . $line . ':M' . $line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                // $total_money += $v['total'];


                // 合计金额
                /* $new_line = $line + 1;
                 $excel->getActiveSheet()->mergeCells('A' . $new_line . ':J' . $new_line);
                 $excel->getActiveSheet()->getRowDimension($new_line)->setRowHeight(24);
                 $excel->getActiveSheet()->setCellValue('A' . $new_line, '金额合计：');
                 $excel->getActiveSheet()->getStyle('A' . $new_line . ':M' . $new_line)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                 $excel->getActiveSheet()->getStyle('A' . $new_line)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
                 $excel->getActiveSheet()->setCellValue('K' . $new_line, $total_money);*/

                //设置单元格边框
                $styleArray = array(
                    'borders' => array(
                        'allborders' => array(
                            //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                            'style' => PHPExcel_Style_Border::BORDER_THIN, //细边框
                            //'color' => array('argb' => 'FFFF0000'),
                        ),
                    ),
                );
                //设置单元格边框
                $excel->getActiveSheet()->getStyle('A1:M2')->applyFromArray($styleArray);
                //垂直居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
                //水平居中
                $excel->getActiveSheet()->getStyle('A1:M2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

                //创建Excel输入对象
                $write = new PHPExcel_Writer_Excel5($excel);
                header("Pragma: public");
                header("Expires: 0");
                header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
                header("Content-Type:application/force-download");
                header("Content-Type:application/vnd.ms-execl");
                header("Content-Type:application/octet-stream");
                header("Content-Type:application/download");
                header('Content-Disposition:attachment;filename="新增重销统计' . date("Y-m-d_H:i:s", $_SERVER['REQUEST_TIME']) . '.xls"');
                header("Content-Transfer-Encoding:binary");
                $write->save('php://output');
            } else {
                header("Content-type: text/html; charset=utf-8");
                echo "没有要导出的数据";die;
            }


        }

    }

    //热销商品
    public function bestsellers()
    {
        $priv = array($this->_pvprefix . "_sal");

        $model = $this->model;
        $auth  = $model->checkPriv($priv);
        if ($auth) {
            $this->view->auth = $auth;
            $this->view->cate = $model->getCategory();

            if ($_GET['start_time'] != "") {
                $para['start_time'] = strtotime($_GET['start_time']);
            }

            if ($_GET['end_time'] != "") {
                $para['end_time'] = strtotime($_GET['end_time'] . " 23:59:59");
            }

            if ($_GET['caid'] != "") {
                $para['caid'] = intval($_GET['caid']);
            }

            $this->view->data = $model->getBestsell($para);

            $this->display();
        }
    }

}
